﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace _6.ParseDouble
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;

            input = "1 23 5 324,12";
            PrintDouble(input);
        }

        private static void PrintDouble(string input)
        {
            double d;

            if (TryParseDouble(input, out d))
            {
                Console.WriteLine(d);
            }
            else
            {
                Console.WriteLine("parse failed");
            }
        }

        private static bool TryParseDouble(string input, out double d)
        {
            input = input.Trim(); 
            input = input.Replace(',', '.'); 
            input = input.Replace(' ', ','); 

            Console.WriteLine(input); 

            if (Double.TryParse(input, NumberStyles.Any, CultureInfo.CreateSpecificCulture("en-US"), out d))
            {
                return true; 
            }

            return false; 
        }
    }
}
